<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Manazra.Controllers.ArticleViewModel>" %>
<%@ Import Namespace="Manazra.Helpers" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	<%= Html.Encode(Model.Article.Title) %>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <%  //logged in user
        Manazra.Models.UserAuth UserAuth = (Manazra.Models.UserAuth)ViewData["UserAuth"];       
    %>

    <h2><%= Html.Encode(Model.Article.Title) %></h2>
    <div class="info">                
        Posted by <%= Html.FormatUserName(Model.Article.Author, true) %> 
        at <%= Html.Encode(String.Format("{0:g}", Model.Article.CreatedDate)) %>
    </div>
    
    <% if (Model.Article.IsAuthor(UserAuth.UserName)) { %>
        <div>
            <%= String.Format("<a href='/Articles/Edit/{0}'>{{Edit Article}}</a>", Model.Article.RecId) %>
            <%= String.Format("<a href='/Articles/Delete/{0}'>{{Delete Article}}</a>", Model.Article.RecId) %>     
        </div>
        <div>&nbsp;</div>
    <% } %>
    
    <% foreach (var segment in Model.Article.ArticleSegments) { %>
        <div class="pentry">
            <%= HttpUtility.HtmlDecode(segment.Content) %>                       
            <div class="commentsection">
                <div class="label1">
                    <div class="right"><a href=# rel="lnkCloseComments">close</a></div>                    
                    Discussion Thread                    
                </div>                        
                <% if (UserAuth.Authenticated) { %><div class="commentlink"><a href="#" rel="lnkComment-<%=segment.RecId %>">Comment on this paragraph</a></div><%} %>
               
                <% foreach (var comment in segment.Comments.OrderByDescending(c=>c.PostedDate)) {
                       string img = "";
                       if (comment.PostedBy.Equals(UserAuth.UserName, StringComparison.InvariantCulture))
                           img = "<img class=\"crbutton\" src=\"/Content/Images/close.png\" alt=\"delete\" title=\"delete\" rel=\"del-" + comment.RecId + "\" />";
                       else if(UserAuth.Authenticated)
                           img = "<img class=\"crbutton\" src=\"/Content/Images/pencil.png\" alt=\"reply\" title=\"reply\" rel=\"reply-" + comment.RecId + "\" />";
                       %>
                    <div class="postedcomment">
                        <div class="cr">
                            <%= img %>
                            <div class="info"><a href="#"><%= Html.FormatUserName(comment.PostedBy, true) %></a> wrote at <%= Html.Encode(String.Format("{0:g}", comment.PostedDate)) %></div>
                        </div>
                        <div><%= comment.CommentType.DisplayHtml %><%= Html.Encode(comment.Content)%></div>
                        <% foreach (var reply in comment.Replies.OrderByDescending(r => r.PostedDate)) { %>
                            <div class="postedreply">
                                <div>
                                    <% if (reply.PostedBy.Equals(UserAuth.UserName, StringComparison.InvariantCulture)) { %><img class="crbutton" src="../../Content/Images/close.png" alt="delete" title="delete" rel="delreply-<%= reply.RecId %>" /><% } %>
                                    <div class="info"><%= Html.FormatUserName(reply.PostedBy, true) %> wrote at <%= Html.Encode(String.Format("{0:g}", reply.PostedDate)) %></div>
                                </div>
                                <div><%= Html.Encode(reply.Content) %></div>
                            </div>
                        <%} %>
                    </div>
                <%} %>
            </div>
            <div class="divider"></div>
        </div>
    <% } %>
    
    <p>
        <a href="/Articles">Back to Articles Listing</a>
    </p>

</asp:Content>

